const express = require('express')
const app = express()

// http://127.0.0.1/api/get
app.get('/api/get', (req, res) => {
  throw new Error('异常')
  res.send('Hello world!')
})

// 中间件
const middleware = (err, req, res, next) => {
  console.log(err)
  res.send(err.message)
}

// 先注册接口、路由，后注册错误级别中间件
app.use(middleware)

app.listen(80, () => {
  console.log('Server running at http://127.0.0.1')
})
